import { Service , Inject } from "typedi";
import {ContinentEntity} from '../entity/ContinentEntity'
import {CountryEntity} from '../entity/CountryEntity'
import {ThinkEntity} from '../entity/ThinkEntity'
import { getRepository } from "typeorm";


@Service()
export class CountryDao{
    public async getAllCountry(): Promise<any> {

        return await     getRepository(ContinentEntity)
                            .createQueryBuilder("ContinentEntity")
                            .leftJoinAndSelect("ContinentEntity.Countrys", "CountryEntity")
                            .getMany();
    }

    public async getAllTime(country_Id:number): Promise<any> {

        return await     getRepository(CountryEntity)
                            .createQueryBuilder("CountryEntity")
                            .where("id = :id", { id: country_Id })
                            .leftJoinAndSelect("CountryEntity.Times", "TimeEntity")
                            .getOne();
    }

    public async getAllThink(country_Id:number,think_Page:number,think_Count:number,time_Id:number): Promise<any> {

        return await       getRepository(ThinkEntity)
        .createQueryBuilder("ThinkEntity")
        .where("thinkTimeTimeId = :id", { id: time_Id })
        .skip(think_Page*think_Count)
        .take(think_Count)
        .leftJoinAndSelect('ThinkEntity.think_Country','CountryEntity',)
        .orderBy("ThinkEntity.think_LikeType", "DESC")
        .getMany();
    }

    
}